#include "fileOperationsHeader.h"
char* updateFile(char path[], char filename[])
{
	if(mh==NULL)
		return ERR_VFS_UPDATEFILE_06;
	FILE *fp=fopen(mh->fileSystemLabel,"r+b");
	int currentFileDescriptors=mh->countOfFileDescriptors;
	int maxFileDescriptors=mh->maxDescriptors;
	int noOfBlocks=maxFileDescriptors/2;
	int i=0;
	long j=0;
	FILE *fpHD=fopen(filename,"rb");
	if(fpHD==NULL)
		return ERR_VFS_UPDATEFILE_02;
	fseek(fpHD,0,SEEK_END);
	int size=ftell(fpHD);
	if(size>maxBlockSize)
		return ERR_VFS_UPDATEFILE_04;
	descriptors *d=(descriptors*)malloc(sizeof(descriptors));
	d=(descriptors*)searchBST(path);
	if(d==NULL)
		return ERR_VFS_UPDATEFILE_01;
	int address=(int)arr[d->blockNumber];
	fseek(fp,address,SEEK_SET);
	rewind(fpHD);
	char *str=(char*)malloc(sizeof(char)*size);
	fread(str,size,1,fpHD);
	fwrite(str,size,1,fp);
	int iterDescriptors=0;
	int fdIter=0;
	while(iterDescriptors<maxFileDescriptors)
	{
		if(strcmp(h->desc[iterDescriptors].location,d->location)==0 && strcmp(h->desc[iterDescriptors].fileName,d->fileName)==0 && h->desc[iterDescriptors].type=='f')
		{
			fdIter=iterDescriptors;
			break;
		}
		iterDescriptors++;
	}
	d->size=size;
	d->type='f';
	h->desc[fdIter]=*d;
	fclose(fp);
	fclose(fpHD);
	return "SUCCESS";
}
